﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExpressionEvaluator.Expceptions
{
	/// <summary>
	/// Base exception for all Expression Eval exceptions.
	/// </summary>
	public abstract class BaseException : Exception
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="BaseExpception"/> class.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="codeBlock">The code block.</param>
		/// <param name="innerException">The inner exception.</param>
		public BaseException(string message, CodeBlock codeBlock, Exception innerException)
			: base(string.Format("{0}\nCode text: {1}\nCode type: {2}\nPosition: {3}",
				message, codeBlock.Text, codeBlock.CodeType, codeBlock.StartIndex), innerException)
		{
			CodeBlock = codeBlock;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="BaseExpception"/> class.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="codeBlock">The code block.</param>
		public BaseException(string message, CodeBlock codeBlock)
			: base(string.Format("{0}\nCode text: {1}\nCode type: {2}\nPosition: {3}", 
				message, codeBlock.Text, codeBlock.CodeType, codeBlock.StartIndex))
		{
			CodeBlock = codeBlock;
		}

		/// <summary>
		/// Gets the code block that raises exception.
		/// </summary>
		/// <value>The code block that raises exception.</value>
		public CodeBlock CodeBlock
		{
			get;
			private set;
		}
	}
}
